<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>异动解析</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">						
			p {margin:1px}
			ul {margin:1px}	
			li {margin:3px}			
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}			
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script>
	</head>
	<body>
		<div id="towrite" class="fixedBox"></div>
		<script>
			var tt = "";
			var time = "";			
			window.onload = function() {
				var day = new Date();				
				mymonth = day.getMonth()+1;
				myday = day.getDate();
				if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
				if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
				tt = day.getFullYear() + "-" + mymonth + "-" + myday;					
				time = day.getTime(tt);				
				getSource();
				getjx();
				changeStyle();
			}
			
			function load(name) {
				var xhr = new XMLHttpRequest()							
				okStatus = document.location.protocol === "file:" ? 0 : 200;				
				xhr.open('GET', name, false);
				xhr.overrideMimeType("text/html;charset=utf-8");		
				xhr.send(null);
				return xhr.status === okStatus ? xhr.responseText : null;
				
			}
			
			function fileExists(url){
				var isExists;
				$.ajax({
					url:url,
					async:false,
					type:'HEAD',
					timeout:2000,
					error:function(){
						isExists=0;
					},
					success:function(){
						isExists=1;
					}

				});

				if(isExists==1){
					return true;
				}else{
					return false;
				}
			}

			$(function() {
				setInterval(function() {
					getjx();
				},
				500);
			})
					
			
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				obj1.style.left= "0px"; 				
				obj1.style.width= "90%";	
				//obj1.style.height= "620px";		
				obj1.style.fontSize= "14px";	
				obj1.style.whiteSpace= "normal";
			}
			
			function createXmlHttp() {
				if (window.XMLHttpRequest) {
					xmlHttp = new XMLHttpRequest();					
					} else {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");					
				}
			}
			
			var res = [];
			function getSource() {								
				var url = "https://app.jiuyangongshe.com/jystock-app/api/v1/action/field"; 	                			
				createXmlHttp();
				var array = {"date":tt,"pc":1}
				//var array = {"date":"2023-10-13","pc":1}
				xmlHttp.open("POST", url, false);				
				xmlHttp.setRequestHeader("platform", "3");
                xmlHttp.setRequestHeader("timestamp", time);
                xmlHttp.setRequestHeader("token", "0");
				xmlHttp.setRequestHeader("Content-Type", "application/json");
				xmlHttp.withCredentials = true
				xmlHttp.send(JSON.stringify(array)) ;
				
				var data = xmlHttp.responseText
				//document.write(data);					
				//console.log(data);
				var json = JSON.parse(data);					
				json =  json.data;
				
				if(json.length > 1){
					for (var i = 1; i < json.length; i++){						
						var rq = json[i].date;
						var reason = json[i].reason;
						var rc = json[i].name;
						var id = rc.replace(/\./g,"");
						if(i == 1){
							ids = "id" + id;
						}							
						
						var aa = json[i].list;
						for (var j = 0; j < aa.length; j++){	
							var code = aa[j].code;
							var name = aa[j].name;
							var bb = aa[j].article.action_info;
							var lb = bb.num;
							if(lb == null){
								lb = "";
							}
							code = code.replace(/(sh)|(sz)|(bj)/g,"")
							var ztsj = "涨停时间：" + bb.time;
							if(bb.time == null || bb.time ==""){
								ztsj = "";
							}								
							var xq = bb.expound;
							xq = xq.replace(/\n/g, "<br>");
							
							res.push({"code":code,"name":name,"date":rq,"bkmc":rc,"reason":reason,"lb":lb,"expound":xq});
						}	
					}
					console.log(JSON.stringify(res));						
				}				
			}
			
			
			var gpdm = "";
			var gpmc = "";
			var dm ="";	
			function getjx() {
				var u = decodeURI(window.location.href);								
				if(u.indexOf("##") > -1){
					var gp = u.split('##');				
					dm = gp[1];
					gpmc = gp[2];															
				}else{
					dm = "600000";
					gpmc = "浦发银行";					
				}
				if(dm != gpdm){
					gpdm = dm;
					var div = document.getElementById('towrite');
					div.scrollTop = 0; //回到顶部
					div.innerHTML = '<font size="3" color="#FFFF80">异动解析：</font><span style="margin-left:20px;color:#FFFFFF;"><span>' + gpdm + "</span><span style='margin-left:10px;'>" + gpmc + "</span></span>";
					//div.innerHTML += "<p style='color:#FFFF80;'><span>" + gpdm + "</span><span style='margin-left:10px;'>" + gpmc + "</p>";
										
					//当日数据
					var rq = "";
					var a = res.findIndex((v) => {    
						return v.code ===  gpdm;
					});
					if(a > -1){
						var arrfind = res.find(function (item) {
							return item.code == gpdm
						});
						//console.log(arrfind)
						rq = arrfind.date;
						//div.innerHTML += "<p style='color:#FFFFFF;'><span>" + arrfind.code + "</span><span style='margin-left:10px;'>" + arrfind.name + "<span style='margin-left:10px;color:#00FFFF;'>" + arrfind.lb +"</span><span style='margin-left:20px;'>" + arrfind.date + "</p>";
						div.innerHTML += "<p style='margin-top:5px;color:#FFFFFF;'><span>" + arrfind.date +"</span><span style='margin-left:20px;'>" + arrfind.lb + "</p>";																		
						var reason = "";
						if(arrfind.reason != ""){
							reason = arrfind.reason;
						}
						div.innerHTML += "<p style='color:#00FFFF;'>" + arrfind.bkmc + "：<span style='color:#FFD700;'>" + reason + "<span></p>";
						var ss = arrfind.expound.split("<br>");
						var yy = "";
						for (var i = 1; i < ss.length; i++){
							yy += ss[i] + "<br>"; 
						}
						
						div.innerHTML += "<p style='color:#FFFF00;'>" + ss[0] + "</p>";
						div.innerHTML += "<p style='color:#FFFFE0;'>" + yy + "</p>";
					}

					var file = "./异动解析/" + dm + ".txt";	
					if(fileExists(file) == true){
						var text = load(file);
						text = text.replace(/\\"/g,"'").replace(/\\/g,"/");
						if(text != ""){
							if(text.indexOf('}]') > -1){
								var ss = text.split('\r\n');
								var n = 0;
								for (var i = 0; i < ss.length - 1; i++){
									var aa = ss[i].split("}]");
									var arr = JSON.parse(aa[1].replace(/\r\n/g,"").replace(/\n/g,""));
									var rqh = arr.date;									
									if(rqh != rq){
										n++;
										if(n == 1){
											div.innerHTML += "<p style='margin:10px 0px 0px -15px;'><font size='3' color=#00FF00;>&nbsp;&nbsp;&nbsp;&nbsp;历史数据：</font></p>";								
										}
										var h = "";								
										if(n > 1){
											h = "<br>";
										}
										//div.innerHTML += h + "<p style='color:#FFFFFF;'><span>" + arr.code + "</span><span style='margin-left:10px;'>" + arr.name + "<span style='margin-left:10px;color:#00FFFF;'>" + arr.lb +"</span><span style='margin-left:20px;'>" + arr.date + "</p>";
										div.innerHTML += h + "<p style='color:#FFFFFF;'><span>" + arr.date +"</span><span style='margin-left:20px;'>" + arr.lb + "</p>";								
										var reason = "";
										if(arr.reason != ""){
											reason = arr.reason;
										}
										div.innerHTML += "<p style='color:#00FFFF;'>" + arr.bkmc + "：<span style='color:#FFD700;'>" + reason + "<span></p>";
										var bb = arr.expound.split("<br>");
										var yy = "";
										for (var j = 1; j < bb.length; j++){
											yy += bb[j] + "<br>"; 
										}
										
										div.innerHTML += "<p style='color:#FFFF00;'>" + bb[0] + "</p>";
										div.innerHTML += "<p style='color:#FFFFE0;'>" + yy + "</p>";
									}
								}
							}
						}							
					}else if(a == -1){
						div.innerHTML += '<p><font size="3">暂无数据</font></p>';
					}
				}	
			}			
		</script>	
	</body>
</html>